package gxdlxy.zx2201.chat5;

import org.omg.SendingContext.RunTime;

import java.io.IOException;

class Person {
    public void finalize() {
        System.out.println("对象将会被回收");
    }
}

public class Example4 {
    public static void main(String[] args) throws IOException {
        long startTime = System.currentTimeMillis();
        System.out.println("代码开始运行时间：" + startTime);

        System.out.println("hello java");
        try {
            int a = 4 / 1;
        } catch (Exception ex) {
            System.out.println("算术异常");
            System.exit(-1);
        }

        // 使用gc回收内存
        Person zhangsan = new Person();
        Person lisi = new Person();
        zhangsan = null;
        lisi = null;
        System.gc();
        for (int i = 0; i < 100000000; i++) ;

        System.out.println(System.currentTimeMillis() - startTime);
        System.out.println("代码结束运行时间：" + System.currentTimeMillis());

        int[] a = new int[]{1, 2, 3, 4, 5};
        int[] b = new int[]{6, 7, 8, 9, 10};
        // 完成数据替换，得到新数组 = {1，2，8，9，5}
        System.arraycopy(b, 2, a, 2, 2);
        for (int i = 0; i < 5; i++)
            System.out.println(a[i]);

        Runtime rt = Runtime.getRuntime();
        rt.exec("C:\\Windows\\notepad.exe");
        System.out.println("空闲内存：" + rt.freeMemory()/1024/1024 + "MB");
        System.out.println("最大内存：" + rt.maxMemory()/1024/1024 + "MB");
        System.out.println("总内存：" + rt.totalMemory()/1024/1024 + "MB");
        System.out.println("CPU核心数：" + rt.availableProcessors());
    }
}
